package com.worldcup.conf.beetl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author duwan.zq
 * @date 2018/12/08
 */
@Configuration
@ConfigurationProperties(prefix = BeetlProperties.BEETL_CONF_PREFIX)
public class BeetlProperties {

    public static final String BEETL_CONF_PREFIX = "beetl";

    private String delimiterStatementStart;

    private String delimiterStatementEnd;

    private String resourceTagRoot;

    @Value("${beetl-beetlsq.dev:true}")
    private boolean dev;

    public Properties getProperties(){
        Properties properties = new Properties();
        if(StringUtils.isNotEmpty(delimiterStatementStart)){
            if(delimiterStatementStart.startsWith("\\")){
                delimiterStatementStart = delimiterStatementStart.substring(1);
            }
            properties.setProperty("DELIMITER_STATEMENT_START",delimiterStatementStart);
        }
        if(StringUtils.isNotEmpty(delimiterStatementEnd)){
            properties.setProperty("DELIMITER_STATEMENT_END",delimiterStatementEnd);
        }else{
            properties.setProperty("DELIMITER_STATEMENT_END","null");
        }
        if(StringUtils.isNotEmpty(resourceTagRoot)){
            properties.setProperty("RESOURCE.tagRoot",resourceTagRoot);
        }
        if (this.dev) {
            properties.put("RESOURCE.autoCheck", "true");
        }
        return properties;
    }

    public String getDelimiterStatementStart() {
        return delimiterStatementStart;
    }

    public void setDelimiterStatementStart(String delimiterStatementStart) {
        this.delimiterStatementStart = delimiterStatementStart;
    }

    public String getDelimiterStatementEnd() {
        return delimiterStatementEnd;
    }

    public void setDelimiterStatementEnd(String delimiterStatementEnd) {
        this.delimiterStatementEnd = delimiterStatementEnd;
    }

    public String getResourceTagroot() {
        return resourceTagRoot;
    }

    public void setResourceTagroot(String resourceTagroot) {
        this.resourceTagRoot = resourceTagroot;
    }
}
